#pragma once
#include <game/controls/Control.h>
#include <boost/shared_ptr.hpp>
#include <Signals.h>
#include <CompilerFeatures.h>
#include <xml/Object.h>

namespace liba {
class Atom;
class Object2D;
} // namespace liba

ARELLO_GAME_NAMESPACE_DECL_START
namespace input {
struct TouchEvent;
} // namespace input

namespace controls {

class Button;


class ButtonLoader
	: public xml::ObjectANSI
{
private:
	virtual bool on_node(xml::Provider * prov, const std::string & name);

public:
	ButtonLoader(Button *btn);

private:
	Button *btn;
};


class Button
	: public game::controls::Control
{
public:
	static boost::shared_ptr<game::controls::Control> Creator(const liba::Atom& name, liba::Object2D* o2d);
	Button(const liba::Atom& name, liba::Object2D* o2d);
	
	virtual liba::xml::ObjectANSI* GetLoader() LIBA_OVERRIDE { return &loader; }

public:
	virtual game::controls::InputSharingMode GetSharingMode() LIBA_OVERRIDE;
	virtual void OnTouchStarted(const game::input::TouchEvent& ev) LIBA_OVERRIDE;
	virtual void OnTouchMove(const game::input::TouchEvent& ev) LIBA_OVERRIDE;
	virtual void OnTouchFinished(const game::input::TouchEvent& ev) LIBA_OVERRIDE;

	liba::signals::signal<void (const Control*)>& Click() { return click; }

private:
	liba::signals::signal<void (const Control*)> click;
	ButtonLoader loader;
};

} // namespace controls
ARELLO_GAME_NAMESPACE_DECL_END
